//
//  UIBarButtonItem+YLJExtension.m
//  ACE
//
//  Created by Mickey Yin on 2021/12/9.
//

#import "UIBarButtonItem+YLJExtension.h"

@implementation UIBarButtonItem (YLJExtension)

+ (instancetype)itemWithTitle:(NSString *)title target:(id)target action:(SEL)action{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    if (title.length) {
        [button setTitle:[NSString stringWithFormat:@"%@", title] forState:UIControlStateNormal];
    }
    button.titleLabel.font = FONT(14);
    [button setTitleColor:RGBGlobal333 forState:UIControlStateNormal];
    button.size = CGSizeMake(30, 30);
    if (action && target) {
        [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    }
    return [[UIBarButtonItem alloc] initWithCustomView:button];
}

+ (instancetype)itemWithImage:(NSString *)image highImage:(NSString *)highImage target:(id)target action:(SEL)action {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
       [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
       // 设置图片
       [button setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
       button.adjustsImageWhenHighlighted = NO;
       [button setImage:[UIImage imageNamed:highImage] forState:UIControlStateHighlighted];
       // 设置尺寸
       button.size = CGSizeMake(35, 35);
       button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
       return [[UIBarButtonItem alloc] initWithCustomView:button];
}

@end
